//
//  MagcCard.h
//  arq
//
//  Created by xiao wen on 15/1/14.
//  Copyright (c) 2015年 witsi. All rights reserved.
//

#include "DataType.h"

#define MAGCCARD_ACCOUNT_MASK_MAXLEN        10
#define MAGCCARD_ACCOUNT_EXPIREDATE_MAXLEN  4
#define MAGCCARD_ACCOUNT_SVR_MAXLEN         3

#define MAGCCARD_ALGORITHM_PARAMETERS_MAXLEN     1006

class ArqSimpleTransceiver;

class MagcCard
{
private:
    static string TAG;
    

    // specify which and how to read the tracks
    byte readFlag = 0x07;

    // Master account mask
    byte mActMask[MAGCCARD_ACCOUNT_MASK_MAXLEN];

    // wait timeout
    int mTimeout = 5000;

    // Algorithm identifier
    byte algID = 0x00;

    // Buffer of algorithm parameters
    vector<byte> algParaBuf;

    byte psamNo = 0;

public:
    void setReadFlag(int flag);
    
    void setCheckIcc(boolean isCheck);
    void setCheckRf(boolean isCheck);
    
    void setMainAccountMask(byte *mask, int maskLen);
    void setTimeout(int ms);
  

    int getTimeout();

    void setAlgorithmId(int id);

    void setAlgorithmPara(byte *buf, int bufLen);

     

    void setPsamNo(int no);


    boolean buildTransceiver(ArqSimpleTransceiver* trans);
    

    /*****************************************************/
    byte mAccount[MAGCCARD_ACCOUNT_MASK_MAXLEN];
    byte mExpireDate[MAGCCARD_ACCOUNT_EXPIREDATE_MAXLEN];
    byte mSvr[MAGCCARD_ACCOUNT_SVR_MAXLEN];
    vector<byte> *track1 = NULL;
    vector<byte> *track2 = NULL;
    vector<byte> *track3 = NULL;

    /* return:
    *	0 --- success.
    * 	-1 --- No frame received yet.
    *	-2 --- bad argument. */
    int analyseTransceiver(ArqSimpleTransceiver* trans);
   

    // return: NULL: track1 not present or decode failed.
    byte *getExpireDate();
   

    // return: NULL: track1 not present or decode failed.
    byte *getSvr();

    // return: NULL: track2 not present or decode failed.
    vector<byte>* getTrack1Data();

    // return: NULL: track2 not present or decode failed.
    vector<byte>* getTrack2Data();

    // return: NULL: track3 not present or decode failed.
    vector<byte>* getTrack3Data();


    byte *getMainAccount();
    
};

